<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-parameter-edit" th:object="${parameter}">
            <input id="id" name="id" th:field="*{id}"  type="hidden">
            <div class="form-group">	
                <label class="col-sm-2 control-label">入校开始时间：</label>
                <div class="col-sm-4">
                    <input id="inSTime" name="inSTime" th:field="*{inSTime}" class="form-control required time" type="text">
                </div>
                <label class="col-sm-2 control-label">入校结束时间：</label>
                <div class="col-sm-4">
                    <input id="inETime" name="inETime" th:field="*{inETime}" class="form-control required time" type="text">
                </div>
            </div>
            <div class="form-group">	
                <label class="col-sm-2 control-label">出校开始时间：</label>
                <div class="col-sm-4">
                    <input id="outSTime" name="outSTime" th:field="*{outSTime}" class="form-control required time" type="text">
                </div>
                <label class="col-sm-2 control-label">出校结束时间：</label>
                <div class="col-sm-4">
                    <input id="outETime" name="outETime" th:field="*{outETime}" class="form-control required time" type="text">
                </div>
            </div>
            <div class="form-group">	
                <label class="col-sm-2 control-label">通知模板：</label>
                <div class="col-sm-10">
                	<textarea rows="5" cols="5" class="form-control required" name="noticeTemplate" th:field="*{noticeTemplate}"></textarea>
                </div>
            </div>
            <div class="form-group">	
				<label class="col-sm-2 control-label">说明：</label>
				<div class="col-sm-10">
					<p>[parent]：表示家长姓名</p>
					<p>[student]：表示学生姓名</p>
					<p>[time]：表示时间</p>
					<p>[status]：表示入校/出校状态</p>
				</div>
			</div>
			<div class="form-group">
				<div class="form-control-static col-sm-offset-9">
					<button type="submit" class="btn btn-primary">提交</button>
					<button onclick="$.modal.close()" class="btn btn-danger" type="button">关闭</button>
				</div>
			</div>
		</form>
    </div>
    <div th:include="include::footer"></div>
    <script type="text/javascript">
	    lay('.time').each(function(){
	    	laydate.render({
	    	  elem: this
	   		  ,type: 'time'
				,trigger: 'click'
	    	});
		});
    
		var prefix = ctx + "module/parameter"
		$("#form-parameter-edit").validate({
			rules:{
				xxxx:{
					required:true,
				},
			},
			submitHandler: function(form) {
				var in_s = $("#inSTime").val();
				var in_e = $("#inETime").val();
				var out_s = $("#outSTime").val();
				var out_e = $("#outETime").val();
				if(!compareTime(in_s,in_e)){
					layer.tips('入校结束时间必须大于入校开始时间', '#inETime', {
					  tips: [1, '#3595CC'],
					  time: 3000
					});
					return false;
				}else if(!compareTime(in_e,out_s)){
					layer.tips('出校开始时间必须大于入校结束时间', '#outSTime', {
					  tips: [1, '#3595CC'],
					  time: 3000
					});
					return false;
				}else if(!compareTime(out_s,out_e)){
					layer.tips('出校结束时间必须大于出校开始时间', '#outETime', {
					  tips: [1, '#3595CC'],
					  time: 3000
					});
					return false;
				}else{
					$.operate.save(prefix + "/save", $('#form-parameter-edit').serialize());
				}
			}
		});
		
		//时间比较
		function compareTime(stime,etime){
			var s_str = stime.split(":");
			var e_str = etime.split(":");
			if(s_str[0]>e_str[0]){
				return false;		
			}else if(s_str[0]==e_str[0] && s_str[1]>e_str[1]){
				return false;
			}else if(s_str[0]==e_str[0] && s_str[1]==e_str[1] && s_str[2]>e_str[2]){
				return false;
			}
			return true;
		}
	</script>
</body>
</html>
